package com.corona.game;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Vector2;
import com.corona.Game;
import com.corona.game.util.SmolSprite;
import com.corona.game.util.TextureCache;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Locale;
import java.util.Objects;

/* compiled from: Battle.java */
/* access modifiers changed from: package-private */
/* loaded from: pokewilds.jar:com/pkmngen/game/CatchPokemonWobblesThenCatch.class */
public class CatchPokemonWobblesThenCatch extends Action {
    ArrayList<Sprite> sprites;
    Sprite sprite;
    ArrayList<Integer> repeats;
    String sound;
    ArrayList<String> sounds;
    Tile pedistalTile;
    String ballUsed;
    public Action.Layer layer = Action.Layer.gui_120;
    Vector2 position = new Vector2(114.0f, 88.0f);
    ArrayList<Vector2> positions = new ArrayList<>();

    public CatchPokemonWobblesThenCatch(Game game, String ballUsed, Action nextAction) {
        super(new Object[0]);
        this.ballUsed = ballUsed;
        this.nextAction = nextAction;
        TextureCache.get(Gdx.files.internal("pokeball1_color.png"));
        this.positions.add(new Vector2(0.0f, 0.0f));
        for (int i = 0; i < 3; i++) {
            this.positions.add(new Vector2(-1.0f, 0.0f));
            this.positions.add(new Vector2(1.0f, 0.0f));
            this.positions.add(new Vector2(1.0f, 0.0f));
            this.positions.add(new Vector2(-1.0f, 0.0f));
        }
        this.sprites = new ArrayList<>();
        this.sprites.add(null);
        Texture text = TextureCache.get(Gdx.files.internal("pokeball_wiggleSheet1_color.png"));
        this.sprites.add(new Sprite(text, 0, 0, 12, 12));
        this.sprites.add(new Sprite(text, 12, 0, 12, 12));
        this.sprites.add(new Sprite(text, 0, 0, 12, 12));
        this.sprites.add(new Sprite(text, 24, 0, 12, 12));
        this.sprites.add(new Sprite(text, 0, 0, 12, 12));
        this.sprites.add(new Sprite(text, 12, 0, 12, 12));
        this.sprites.add(new Sprite(text, 0, 0, 12, 12));
        this.sprites.add(new Sprite(text, 24, 0, 12, 12));
        this.sprites.add(new Sprite(text, 0, 0, 12, 12));
        this.sprites.add(new Sprite(text, 12, 0, 12, 12));
        this.sprites.add(new Sprite(text, 0, 0, 12, 12));
        this.sprites.add(new Sprite(text, 24, 0, 12, 12));
        this.repeats = new ArrayList<>();
        this.repeats.add(12);
        this.repeats.add(43);
        for (int i2 = 0; i2 < 3; i2++) {
            this.repeats.add(3);
        }
        this.repeats.add(43);
        for (int i3 = 0; i3 < 3; i3++) {
            this.repeats.add(3);
        }
        this.repeats.add(43);
        for (int i4 = 0; i4 < 2; i4++) {
            this.repeats.add(3);
        }
        this.repeats.add(5);
        this.sounds = new ArrayList<>();
        this.sounds.add("pokeball_wiggle1");
        this.sounds.add(null);
        this.sounds.add("pokeball_wiggle1");
        for (int i5 = 0; i5 < 3; i5++) {
            this.sounds.add(null);
        }
        this.sounds.add("pokeball_wiggle1");
        for (int i6 = 0; i6 < 6; i6++) {
            this.sounds.add(null);
        }
    }

    @Override // com.corona.game.Action
    public String getCamera() {
        return "gui";
    }

    @Override // com.corona.game.Action
    public Action.Layer getLayer() {
        return this.layer;
    }

    @Override // com.corona.game.Action
    public void firstStep(Game game) {
        for (Tile tile : game.map.tiles.values()) {
            if (tile.name.contains("cave1_regipedistal1")) {
                this.pedistalTile = tile;
                return;
            }
        }
    }

    @Override // com.corona.game.Action
    public void step(Game game) {
        DrawBattle.shouldDrawOppPokemon = false;
        if (this.positions.isEmpty() || this.sprites.isEmpty()) {
            if (game.battle.oppPokemon.standingAction != null) {
                game.battle.oppPokemon.removeDrawActions(game);
                game.battle.oppPokemon.standingAction = null;
                if (game.battle.oppPokemon.isTrapping) {
                    game.map.tiles.get(game.battle.oppPokemon.position).items.remove(game.battle.oppPokemon.specie.name.toLowerCase(Locale.ROOT));
                    game.map.burrowedPokemon.remove(game.battle.oppPokemon.position);
                } else {
                    game.map.pokemon.remove(game.battle.oppPokemon.position);
                }
            }
            if (game.battle.oppPokemon.isTrapping) {
                game.map.tiles.get(game.battle.oppPokemon.position).items.remove(game.battle.oppPokemon.specie.name.toLowerCase(Locale.ROOT));
            }
            PokemonCaughtEvents newAction = new PokemonCaughtEvents(game, new DisplayText(game, "All right! " + game.battle.oppPokemon.nickname.toUpperCase(Locale.ROOT) + " was caught!", "catch_fanfare.ogg", (Action) null, (Action) null));
            if (Game.catchExpEnabled) {
                ArrayList<Pokemon> participated = new ArrayList<>();
                Iterator<Pokemon> it = game.player.pokemon.iterator();
                while (it.hasNext()) {
                    Pokemon pokemon = it.next();
                    if (!pokemon.isEgg && pokemon.level < 100 && pokemon.currentStats.get("hp").intValue() > 0) {
                        if (pokemon == game.player.currPokemon) {
                            participated.add(0, pokemon);
                        } else {
                            participated.add(pokemon);
                        }
                    }
                }
                if (!participated.isEmpty()) {
                    int expAmount = game.battle.calcFaintExp(participated.size());
                    newAction.append(new DisplayText(game, game.player.name.toUpperCase(Locale.ROOT) + "' POKéMON gained " + String.valueOf(expAmount) + " EXP. Points!", (String) null, (Action) null, (Action) null));
                    Iterator<Pokemon> it2 = participated.iterator();
                    while (it2.hasNext()) {
                        Pokemon pokemon2 = it2.next();
                        pokemon2.exp += expAmount;
                        if (pokemon2 == game.player.currPokemon) {
                            newAction.append(new GainExpAnimationGen2(pokemon2, null));
                        } else {
                            newAction.append(new GainExpAnimation(pokemon2, null));
                        }
                    }
                    Iterator<Pokemon> it3 = participated.iterator();
                    while (it3.hasNext()) {
                        newAction.append(new CheckEvo(it3.next(), null));
                    }
                }
            }
            newAction.append(new SetField(newAction, "done", true, new SplitAction(new BattleFadeOut(game, null), new BattleFadeOutMusic(game, null))));
            if (!game.battle.oppPokemon.specie.name.contains("regi")) {
                newAction.append(new SetField(game.musicController, "resumeOverworldMusic", true, null));
            }
            game.battle.oppPokemon.previousOwner = game.player;
            game.battle.oppPokemon.aggroPlayer = false;
            game.battle.oppPokemon.cantEscapeBy = null;
            game.battle.oppPokemon.volatileStatus.clear();
            game.battle.oppPokemon.volatileStatusCounter.clear();
            if (game.player.pokemon.size() < 6) {
                game.player.pokemon.add(game.battle.oppPokemon);
            } else {
                game.battle.oppPokemon.position = game.player.spawnLoc.cpy();
                game.battle.oppPokemon.mapTiles = game.map.overworldTiles;
                if (game.player.spawnIndex != -1) {
                    game.battle.oppPokemon.mapTiles = game.map.interiorTiles.get(game.player.spawnIndex);
                    game.battle.oppPokemon.interiorIndex = game.player.spawnIndex;
                }
                newAction.append(new DisplayText(game, "Your party is full! " + game.battle.oppPokemon.nickname.toUpperCase(Locale.ROOT) + " was sent to the last safe place.", (String) null, (Action) null, (Action) null));
                Pokemon pokemon3 = game.battle.oppPokemon;
                Objects.requireNonNull(pokemon3);
                game.insertAction(new Pokemon.Standing());
            }
            if (SpecialMewtwo1.class.isInstance(game.battle.oppPokemon)) {
                Tile tile = ((SpecialMewtwo1) game.battle.oppPokemon).tile;
                tile.nameUpper = "";
                tile.init();
                if (game.battle.oppPokemon.isShiny) {
                    game.battle.oppPokemon.sprite = game.battle.oppPokemon.specie.spriteShiny;
                } else {
                    game.battle.oppPokemon.sprite = game.battle.oppPokemon.specie.sprite;
                }
            } else if (game.battle.oppPokemon.onTile != null && game.battle.oppPokemon.onTile.nameUpper.contains("revived_")) {
                game.battle.oppPokemon.onTile.nameUpper = "";
            } else if (game.battle.oppPokemon.onTile != null && game.battle.oppPokemon.onTile.nameUpper.equals("volcarona")) {
                Tile tile2 = game.battle.oppPokemon.onTile;
                tile2.nameUpper = "";
                tile2.init(tile2.name, tile2.nameUpper, tile2.position, true, tile2.routeBelongsTo);
            } else if (game.battle.oppPokemon.onTile == null || !game.battle.oppPokemon.onTile.nameUpper.equals("spiritomb")) {
                game.map.currRoute.storedPokemon.remove(game.battle.oppPokemon);
            } else {
                Tile tile3 = game.battle.oppPokemon.onTile;
                tile3.nameUpper = "";
                tile3.init();
            }
            if (game.player.pokemon.size() >= 6 && !game.player.displayedMaxPartyText) {
                game.player.displayedMaxPartyText = true;
                newAction.append(new DisplayText(game, "Your party is full! You will need to DROP some of them in order to catch more.", (String) null, (Action) null, (Action) null));
            }
            if (game.battle.oppPokemon.specie.name.equals("regigigas")) {
                Tile regiTile = null;
                Iterator<Tile> it4 = game.map.tiles.values().iterator();
                while (true) {
                    if (!it4.hasNext()) {
                        break;
                    }
                    Tile tile4 = it4.next();
                    if (tile4.name.contains("cave1_regi3")) {
                        regiTile = tile4;
                        break;
                    }
                }
                game.map.tiles.remove(regiTile.position);
                newAction.append(new SetField(game, "playerCanMove", true, null));
            } else if (this.pedistalTile != null && game.battle.oppPokemon.specie.name.contains("regi")) {
                String text = "";
                if (this.pedistalTile.nameUpper.equals("REGICE")) {
                    text = "Cold ... very cold ... too cold ... but ... even with heat ... it lasts forever ... ";
                } else if (this.pedistalTile.nameUpper.equals("REGIROCK")) {
                    text = "Simple stones ... such a creation ... each one so unique ... but only stones ... even in the head ... ";
                } else if (this.pedistalTile.nameUpper.equals("REGISTEEL")) {
                    text = "Metals ... from underground ... so tough ... so flexible ... yet it' so old ... it has an unearthly presence ... ";
                } else if (this.pedistalTile.nameUpper.equals("REGIDRAGO")) {
                    text = "Such a sad sight ... my child ... its my fault ... incomplete ... just a dragon' head ... but you are still ... so strong ... ";
                } else if (this.pedistalTile.nameUpper.equals("REGIELEKI")) {
                    text = "Such a sad sight ... my child ... your electricity ... restrained ... but ... you are still ... so strong ... ";
                }
                this.pedistalTile.nameUpper = "";
                this.pedistalTile.items().remove(game.battle.oppPokemon.specie.name.toUpperCase(Locale.ROOT));
                this.pedistalTile.init();
                if (this.pedistalTile.items().isEmpty()) {
                    Tile regiTile2 = null;
                    Iterator<Tile> it5 = game.map.tiles.values().iterator();
                    while (true) {
                        if (!it5.hasNext()) {
                            break;
                        }
                        Tile tile5 = it5.next();
                        if (tile5.name.contains("cave1_regi2")) {
                            regiTile2 = tile5;
                            break;
                        }
                    }
                    this.pedistalTile.sprite = new SmolSprite(TextureCache.get(Gdx.files.internal("tiles/cave1/cave1_floor2.png")), 0, 0, 16, 16);
                    this.pedistalTile.sprite.setPosition(this.pedistalTile.position.x, this.pedistalTile.position.y);
                    this.pedistalTile.name = "cave1_floor2";
                    this.pedistalTile.isSolid = false;
                    newAction.append(new DisplayText(game, text + "My work is ... complete...", (String) null, (Action) null, true, (Action) new SetField(regiTile2, "name", "cave1_regi3", null)));
                } else {
                    this.pedistalTile.overSprite = new SmolSprite(TextureCache.get(Gdx.files.internal("tiles/cave1/cave1_regipedistal1.png")), 0, 0, 16, 16);
                    this.pedistalTile.overSprite.setPosition(this.pedistalTile.position.x, this.pedistalTile.position.y);
                    newAction.append(new DisplayText(game, text + "I desire more ...", (String) null, (Action) null, true, (Action) new RegigigasOutroAnim(null)));
                }
                newAction.append(new SetField(game.musicController, "resumeOverworldMusic", true, null));
            }
            if (this.ballUsed.equals("heal ball")) {
                Pokemon pokemon4 = game.battle.oppPokemon;
                Objects.requireNonNull(pokemon4);
                newAction.append(new Pokemon.SetStat("hp", game.battle.oppPokemon.maxStats.get("hp").intValue(), new SetField(game.battle.oppPokemon, "status", null, null)));
            }
            newAction.append(new WaitFrames(game, 6, new SetField(game, "playerCanMove", true, null)));
            game.insertAction(newAction);
            newAction.step(game);
            game.actionStack.remove(this);
            return;
        }
        this.sound = this.sounds.get(0);
        if (this.sound != null) {
            game.insertAction(new PlaySound(this.sound, (Action) null));
            this.sounds.set(0, null);
        }
        this.sprite = this.sprites.get(0);
        if (this.sprite != null) {
            this.sprite.setPosition(this.position.x, this.position.y);
            this.sprite.draw(game.uiBatch);
        }
        if (this.repeats.get(0).intValue() > 0) {
            this.repeats.set(0, Integer.valueOf(this.repeats.get(0).intValue() - 1));
            return;
        }
        this.position = this.position.add(this.positions.get(0));
        this.positions.remove(0);
        this.sprites.remove(0);
        this.repeats.remove(0);
        this.sounds.remove(0);
    }
}
